public class Solution1267 {
    public int countServers(int[][] grid) {
        int ans=0;
        for (int i=0;i<grid.length;i++){
            int total=0;
            for (int j=0;j<grid[0].length;j++){
                if (grid[i][j]==1){
                    total++;
                }
            }
            if (total>=2){
                for (int j=0;j<grid[0].length;j++){
                    if (grid[i][j]==1){
                        grid[i][j]=2;
                    }
                }
                ans+=total;
            }
        }
        for (int i=0;i<grid[0].length;i++){
            int total=0,sub=0;
            for (int[] ints : grid) {
                if (ints[i] > 0) {
                    total++;
                    if (ints[i] == 2) {
                        sub++;
                    }
                }
            }
            if (total>=2){
                ans+=total-sub;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1267().countServers(new int[][]{{1,0},{1,1}}));
    }
}
